package com.jjyu.controller;

import com.jjyu.entity.Preference;
import com.jjyu.service.PreferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/preferences")
public class PreferenceController {

    @Autowired
    private PreferenceService preferenceService;

    @PostMapping
    public ResponseEntity<String> addPreference(@RequestBody Preference preference) {
        boolean result = preferenceService.addPreference(preference);
        if (result) {
            return ResponseEntity.ok("Preference added successfully");
        } else {
            return ResponseEntity.badRequest().body("Failed to add preference");
        }
    }

    @PutMapping("/{prefId}")
    public ResponseEntity<String> updatePreference(@PathVariable int prefId, @RequestBody Preference preference) {
        preference.setPrefId(prefId);
        boolean result = preferenceService.updatePreference(preference);
        if (result) {
            return ResponseEntity.ok("Preference updated successfully");
        } else {
            return ResponseEntity.badRequest().body("Failed to update preference");
        }
    }

    @DeleteMapping("/{prefId}")
    public ResponseEntity<String> deletePreference(@PathVariable int prefId) {
        boolean result = preferenceService.deletePreference(prefId);
        if (result) {
            return ResponseEntity.ok("Preference deleted successfully");
        } else {
            return ResponseEntity.badRequest().body("Failed to delete preference");
        }
    }
}